//
//  NearbyCell.m
//  糗事百科
//
//  Created by 奚超明 on 16/5/31.
//  Copyright © 2016年 奚超明. All rights reserved.
//

#import "NearbyCell.h"
#import "NearbyModel.h"

@interface NearbyCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *ageAndSexBtn;
@property (weak, nonatomic) IBOutlet UIButton *astrologyBtn;
@property (weak, nonatomic) IBOutlet UILabel *distanceLabel;

@end

@implementation NearbyCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    // 头像圆角
    self.iconImageView.layer.cornerRadius = self.iconImageView.xcm_width * 0.5;
    self.iconImageView.layer.masksToBounds = YES;
    
    // 年龄及星座按钮圆角
    self.ageAndSexBtn.layer.cornerRadius = 4;
    self.ageAndSexBtn.layer.masksToBounds = YES;
    self.astrologyBtn.layer.cornerRadius = 4;
    self.astrologyBtn.layer.masksToBounds = YES;
}

- (void)setNearbyModel:(NearbyModel *)nearbyModel
{
    _nearbyModel = nearbyModel;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:nearbyModel.icon]];
    self.nameLabel.text = nearbyModel.name;
    [self.ageAndSexBtn setTitle:[nearbyModel.age stringValue] forState:UIControlStateNormal];
    
    if ([nearbyModel.gender isEqualToString:@"M"]) {
        [self.ageAndSexBtn setImage:[UIImage imageNamed:@"man"] forState:UIControlStateNormal];
    } else {
        [self.ageAndSexBtn setImage:[UIImage imageNamed:@"woman"] forState:UIControlStateNormal];
    }
    
    [self.astrologyBtn setTitle:[nearbyModel.astrology substringToIndex:2] forState:UIControlStateNormal];
    self.distanceLabel.text = [NSString stringWithFormat:@"%zd.%zdkm", [nearbyModel.dis integerValue] / 1000, [nearbyModel.dis integerValue] % 1000 / 100];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
